package com.example.query.sdcard;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter{
	
	private Context mContext;
	private LayoutInflater mInflater;
	private ArrayList<Item> listItem = new ArrayList<Item>();
	
	public ListAdapter(Context c, ArrayList<Item> listItem) {
		// TODO Auto-generated constructor stub
		this.mContext = c;
		this.mInflater = LayoutInflater.from(c);
		this.listItem = listItem;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return this.listItem.size();
	}

	public Object getItem(int pos) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int pos) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int pos, View view, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		Item _item = listItem.get(pos);
		if (view == null) {
			view = mInflater.inflate(R.layout.item, null);
			holder = new ViewHolder();
			holder.title = (TextView) view.findViewById(R.id.nameOfItem);
			holder.icon = (ImageView) view.findViewById(R.id.imgOfItem);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		holder.icon.setAdjustViewBounds(true);
		holder.icon.setScaleType(ImageView.ScaleType.CENTER_CROP);
		holder.icon.setImageResource(_item.getIcon());
		holder.title.setText(_item.getNameItem());
		holder.title.setContentDescription(_item.getPathItem());
		
		return view;
	}
	
	public class ViewHolder {
		public TextView title;
		public ImageView icon;
	}

}
